//面包屑
// new Vue().$mount('#crumbs');
var msgId = localStorage.getItem("sendedMsgId");
var sm = new Vue({
    el: "#messageconsultstatistic",
    data: function () {
        return {
            loading: true,
            tag: '1',
            status: 0,
            keyword: '',
            tableData: [],
            total: 0,
            pageSize: 10,
            pageIndex: 1,
            curFilterVal: '0',
            //已查阅，未查阅，全部
            stateCounts: [0, 0, 0],
            visible: true
        }
    },
    computed: {
        curFilter: function () {
            if (this.curFilterVal === "0") {
                return "全部(" + this.stateCounts[2] + ")";
            } else if (this.curFilterVal === "1") {
                return "已查阅(" + this.stateCounts[0] + ")";
            } else {
                return "未查阅(" + this.stateCounts[1] + ")";
            }
        },
        filtersStatusCount: function () {
            return [{
                text: "全部 (" + this.stateCounts[2] + ")",
                value: "0"
            }, {
                text: "已查阅 (" + this.stateCounts[0] + ")",
                value: "1"
            }, {
                text: "未查阅 (" + this.stateCounts[1] + ")",
                value: ""
            }]
        }
    },
    methods: {
        search: function () {
            this.getData(1, this.pageSize, msgId, this.status, this.tag, this.keyword);
            this.curFilterVal = "0";
            this.getNum(msgId, 1, this.tag, this.keyword);
            this.getNum(msgId, 0, this.tag, this.keyword);
            this.getNum(msgId, '', this.tag, this.keyword);
        },
        getNum: function (msgId, status, tag, keyword) {
            VanyAjax("/sendedmsg/getReceiptMsgCount", {
                msgId: msgId,
                receiptStatus: status,
                tag: tag,
                keyword: keyword
            }, "POST").done(function (data) {
                if (status === 1) {
                    this.stateCounts[0] = data;
                } else if (status === 0) {
                    this.stateCounts[2] = data;
                } else {
                    this.stateCounts[1] = data;
                }
                this.stateCounts = [].concat(this.stateCounts);
            }, false, this);
        },
        getData: function (pageIndex, pageSize, msgId, status, tag, keyword) {
            this.loading = true;
            VanyAjax("/sendedmsg/getReceiptMsg", {
                pageIndex: pageIndex,
                pageSize: pageSize,
                msgId: msgId,
                receiptStatus: status,
                tag:tag,
                keyword: keyword
            }, "POST").done(function (data) {
                var msgs = data.list;
                this.tableData = msgs;
                this.total = msgs.length;
                for (var i = 0; i < msgs.length; i++) {
                    this.tableData[i].createTime = new Date((msgs[i].createTime)).Format("yyyy-MM-dd hh:mm:ss")
                    if (msgs[i].receiptStatus === "1") {
                        this.tableData[i].consultTime = new Date((msgs[i].receiptTime)).Format("yyyy-MM-dd hh:mm:ss")
                    } else {
                        this.tableData[i].consultTime = "--";
                    }
                }
                this.pageIndex = data.pageNum;
                this.pageSize = data.pageSize;
                this.total = data.total;
                this.curFilter = "全部(" + msgs.length + ")";
                this.loading = false;
            }, false, this);
        },
        filterStatus: function (command) {
            console.log(command);
            this.curFilterVal = command;
            this.status = command;
            this.getData(1, this.pageSize, msgId, command, this.tag, this.keyword);
        },

        handleCurrentChange: function (val) {
            console.log('当前页:' + val);
            this.getData(val, this.pageSize, msgId, this.status, this.tag, this.keyword);
        },

        handleSizeChange: function (val) {
            this.getData(1, val, msgId, this.status, this.tag, this.keyword);
        }
    },
    mounted: function () {
        this.getData(this.pageIndex, this.pageSize, msgId, this.status, this.tag, this.keyword);
        this.getNum(msgId, 1, this.tag, this.keyword);
        this.getNum(msgId, 0, this.tag, this.keyword);
        this.getNum(msgId, '', this.tag, this.keyword);
    },
})
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,                 //月份
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时
        "m+": this.getMinutes(),                 //分
        "s+": this.getSeconds(),                 //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds()             //毫秒
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};